package com.fyt.reachgo.mapper;

import cn.hutool.core.lang.Pair;
import com.fyt.reachgo.domain.UserLike;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Set;

/**
* @author 27675
* @description 针对表【user_like(用户点赞记录表)】的数据库操作Mapper
* @createDate 2025-03-30 21:06:58
* @Entity com.fyt.reachgo.domain.UserLike
*/
public interface UserLikeMapper extends BaseMapper<UserLike> {


    @Select("SELECT COUNT(1) > 0 FROM user_like WHERE user_id = #{userId} AND guide_id = #{guideId}")
    boolean exists(@Param("userId") Long userId, @Param("guideId") Integer guideId);

    // 批量插入或更新
    @Insert("<script>" +
            "INSERT INTO user_like (user_id, guide_id, create_time) VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.userId}, #{item.guideId}, #{item.createTime})" +
            "</foreach>" +
            " ON DUPLICATE KEY UPDATE create_time = VALUES(create_time)" +
            "</script>")
    void batchInsert(@Param("list") List<UserLike> userLikes);

    // 批量删除（使用 IN 语法，更高效）
    @Delete("<script>" +
            "DELETE FROM user_like WHERE (user_id, guide_id) IN " +
            "<foreach collection='list' item='item' open='(' separator=',' close=')'>" +
            "(#{item.userId}, #{item.guideId})" +
            "</foreach>" +
            "</script>")
    void batchDelete(@Param("list") List<UserLike> userLikes);



}



